import Reqwest from '../../utils/Reqwest';
import {PlatFormBean} from './PlatForm';
import {base, assign, redirect}  from '../base/Base';
import {ResponseDto} from '../base/BaseDTO';
declare let GLOBAL: any;

export class PlatFormController {
    path = `${GLOBAL.baseApiUrl}/adPlatform/api`;

    /**
     * searchPlatForm
     * 查询PlatForm列表
     * @param {*} [params] 
     * @param {any} [options={}] 
     * @returns {Promise<any>} 
     * 
     * @memberOf PlatFormController
     */
    searchPlatForm(params?: any, options = {}): Promise<any> {
        return new Reqwest(assign({
            url: `${this.path}/list.jhtml`,
            method: 'get',
            type: 'json',
            contentType: 'application/json; charset=UTF-8',
            data: params || {},
            headers: {
                'X-CSRF-TOKEN': base._csrf
            }
        }, options)).catch(redirect);
    }

    /**
     * getPlatForm
     * 根据ID查询PlatForm信息
     * @param {{
     *         id: number
     *     }} [params] 
     * @param {any} [options={}] 
     * @returns {Promise<ResponseDto<PlatFormBean<any>>>} 
     * 
     * @memberOf PlatFormController
     */
    getPlatForm(params?: {
        id: number
    }, options = {}): Promise<ResponseDto<PlatFormBean<any>>> {
        return new Reqwest(assign({
            url: `${this.path}/getView.jhtml`,
            method: 'get',
            type: 'json',
            contentType: 'application/json; charset=UTF-8',
            data: params || {},
            headers: {
                'X-CSRF-TOKEN': base._csrf
            }
        }, options)).catch(redirect);
    }

    /**
     * editPlatForm
     * 修改PlatForm
     * @param {PlatFormBean<any>} params 
     * @param {any} [options={}] 
     * @returns {Promise<ResponseDto<any>>} 
     * 
     * @memberOf PlatFormController
     */
    editPlatForm(params: PlatFormBean<any>, options = {}): Promise<ResponseDto<any>> {
        return new Reqwest(assign({
            url: `${this.path}/update.jhtml`,
            method: 'post',
            type: 'json',
            contentType: 'application/json; charset=UTF-8',
            data: JSON.stringify(params) || {},
            headers: {
                'X-CSRF-TOKEN': base._csrf
            }
        }, options)).catch(redirect);
    }

    /**
     * addPlatForm
     * 新增PlatForm
     * @param {PlatFormBean<any>} params 
     * @param {any} [options={}] 
     * @returns {Promise<ResponseDto<any>>} 
     * 
     * @memberOf PlatFormController
     */
    addPlatForm(params: PlatFormBean<any>, options = {}): Promise<ResponseDto<any>> {
        return new Reqwest(assign({
            url: `${this.path}/create.jhtml`,
            method: 'post',
            type: 'json',
            contentType: 'application/json; charset=UTF-8',
            data: JSON.stringify(params) || {},
            headers: {
                'X-CSRF-TOKEN': base._csrf
            }
        }, options)).catch(redirect);
    }

    /**
     * deletePlatForm
     * 删除PlatForm
     * @param {{
     *         id: number
     *     }} [params] 
     * @param {any} [options={}] 
     * @returns {Promise<ResponseDto<any>>} 
     * 
     * @memberOf PlatFormController
     */
    deletePlatForm(params?: {
        id: number
    }, options = {}): Promise<ResponseDto<any>> {
        return new Reqwest(assign({
            url: `${this.path}/delete.jhtml`,
            method: 'get',
            type: 'json',
            contentType: 'application/json; charset=UTF-8',
            data: params || {},
            headers: {
                'X-CSRF-TOKEN': base._csrf
            }
        }, options)).catch(redirect);
    }
}